package com.open.thinks.todo.system.common;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import com.open.thinks.todo.system.domain.helper.EnumContentable;

public class EnumContentableOption {
	private String label;
	private String value;

	public EnumContentableOption() {
		super();
	}

	public EnumContentableOption(EnumContentable enumObject) {
		setLabel(EnumContentHolder.getContent(enumObject));
		setValue(enumObject.toString());
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public static List<EnumContentableOption> options(Class<? extends EnumContentable> enumType) {
		List<EnumContentableOption> options = new ArrayList<EnumContentableOption>();
		try {
			Method method = enumType.getDeclaredMethod("values");
			Object executed = method.invoke(null);
			if (executed.getClass().isArray()) {
				EnumContentable[] enums = (EnumContentable[]) executed;
				for (EnumContentable item : enums) {
					options.add(new EnumContentableOption(item));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return options;
	}
}
